<template>
  <div>
    <a-input :value="formName" placeholder="请选择单据" @click="openModal"/>
    <FormRelationFormSelectorModal @ok="handlOK" ref="FormRelationFormSelectorModal"/>
  </div>
</template>
<script>
import {createProps} from '@/utils';
import FormRelationFormSelectorModal
  from '@comp/hhd/design/relation/FormRelationFormSelector/FormRelationFormSelectorModal.vue';

export default {
  name: 'FormRelationFormSelector',
  components: {FormRelationFormSelectorModal},
  props: {
    formId: createProps(String),
    formName: createProps(String),
    confirmSelect: createProps(Function, undefined)
  },
  methods: {
    handlOK(formDefinition) {
      if(formDefinition.id === this.formId) return
      let callback = () => {
        this.$emit('update:formId', formDefinition.id);
        this.$emit('update:formName', formDefinition.formName);
      }
      if (this.confirmSelect) return this.confirmSelect(callback)
      callback();
    },
    openModal() {
      this.$refs.FormRelationFormSelectorModal.open();
    },
  }
};
</script>